﻿<UserControls:ScrumUserControl x:Class="ScrumTable.UI.View.WinTouch.UserControls.Tool.ScrumInkCanvas"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:s="http://schemas.microsoft.com/surface/2008" xmlns:UserControls="clr-namespace:ScrumTable.UI.View.WinTouch.UserControls" xmlns:CustomControl="clr-namespace:ScrumTable.UI.View.WinTouch.CustomControl" xmlns:Localization="clr-namespace:ScrumTable.UI.View.Localization;assembly=ScrumTable.UI.View"
                               xmlns:Converter="clr-namespace:ScrumTable.UI.View.Converter;assembly=ScrumTable.UI.View"
                               xmlns:Tool="clr-namespace:ScrumTable.UI.View.WinTouch.UserControls.Tool"
                               HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
    <Grid>
        <Grid.Resources>
            <Converter:ConverterBoolVisibility x:Key="BoolVisibility"/>
            <Converter:ConverterNotBoolVisibility x:Key="NotBoolVisibility"/>
            <Converter:ConverterEnumToBrush x:Key="BorderBrushConverter" Value="Blue"/>
            <Converter:ConverterEnumVisibility x:Key="EnumVisibilityConverter"/>
            <Converter:ConverterIsNullVisibility x:Key="IsNullVisbility"/>
            <Converter:ConverterNotBool x:Key="NotBool"/>

            <Style  TargetType="{x:Type s:SurfaceButton}" BasedOn="{StaticResource {x:Type s:SurfaceButton}}" >
                <Setter Property="Height" Value="48" />
                <Setter Property="Width" Value="48" />
                <Setter Property="Margin" Value="3" />
                <Setter Property="Padding" Value="3" />
                <Setter Property="BorderThickness" Value="2" />
                <Style.Triggers>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter Property="OpacityMask" Value="{StaticResource disabledMask}" />
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="True">
                        <Setter Property="OpacityMask" Value="{StaticResource enabledMask}" />
                    </Trigger>
                </Style.Triggers>
            </Style>

            <Style BasedOn="{StaticResource BaseTextStyle}" TargetType="{x:Type CustomControl:ValidateTextBox}">
                <Setter Property="Width" Value="50"/>
                <Style.Triggers>
                    <Trigger Property="IsFocused" Value="True">
                        <Setter Property="Width" Value="150"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>


        <CustomControl:ScrumTableScrollViewer Background="White" Grid.RowSpan="2" >
            <Tool:ScrumTableInkCanvas PreviewTouchDown="OnDrawingPadCanvasInputDown"  PreviewTouchMove="OnDrawingPadCanvasInputChanged" PreviewTouchUp="OnDrawingPadCanvasInputUp" PreviewMouseDown="OnDrawingPadCanvasInputDown"   PreviewMouseMove="OnDrawingPadCanvasInputChanged" PreviewMouseUp="OnDrawingPadCanvasInputUp"  x:Name="DrawingPadCanvas" Background="White" StrokeErasing="OnStrokeErasing" StrokeCollected="OnStrokeCollected" UseCustomCursor="True" Cursor="Cross"  ScrollViewer.HorizontalScrollBarVisibility="Visible"/>
        </CustomControl:ScrumTableScrollViewer>
        <s:SurfaceButton VerticalAlignment="Top" HorizontalAlignment="Right" Width="48" Height="48" Background="Transparent" HorizontalContentAlignment="Center"  VerticalContentAlignment="Top" Click="OnCloseButtonClick" Padding="0" Visibility="{Binding IsFullScreenMode, Converter={StaticResource BoolVisibility}}" >
            <Label Background="{StaticResource IconClose}" Width="48" Height="48"></Label>
        </s:SurfaceButton>

        <Grid Grid.Row="0" Grid.RowSpan="2" Background="{x:Null}" HorizontalAlignment="Left" Grid.Column="0" VerticalAlignment="Top" Margin="5,0,0,0" >
            <!--
            <Rectangle Fill="#FFA4B4BD" HorizontalAlignment="Stretch" Grid.ColumnSpan="2"  />
            -->
            
            <StackPanel Orientation="Vertical" VerticalAlignment="Top" Grid.ColumnSpan="2" Margin="0,5" HorizontalAlignment="Center"  >
                <GroupBox HorizontalAlignment="Left" Localization:Translate.Uid="Ink_File" Header="{Localization:Translate Default=[File]}" >                    <!--Visibility="{Binding IsFullScreenMode, Converter={StaticResource BoolVisibility}}"-->
                    <StackPanel Orientation="Vertical"  HorizontalAlignment="Left" >
                        <s:SurfaceButton HorizontalAlignment="Left"  Background="{StaticResource InkSave }" Click="SaveSurfaceButtonClick" IsEnabled="{Binding Path=CanUndo}" Visibility="{Binding Attachment, Converter={StaticResource IsNullVisbility}}"/>
                        <StackPanel Orientation="Horizontal">
                            <s:SurfaceButton Background="{StaticResource InkSaveAs }" Click="RenameButtonClick"  IsEnabled="{Binding Path=CanUndo}"/>                        
                            <StackPanel Orientation="Horizontal" Name="RenamePanel" Visibility="Collapsed">
                                <CustomControl:ValidateTextBox MaxLength="49" x:Name="FileName" VerticalAlignment="Center" ValidateFileName="True" ValidateRegex=".+"/>
                                <s:SurfaceButton Background="{StaticResource IconCheck }" Click="RenameOkButtonClick" />
                                <s:SurfaceButton Background="{StaticResource IconDelete }" Click="RenameCancelButtonClick" />
                            </StackPanel>
                        </StackPanel>
                    </StackPanel>
                </GroupBox>

                <GroupBox HorizontalAlignment="Left" Localization:Translate.Uid="Ink_Edit" Header="{Localization:Translate Default=[Edit]}"  >
                    <StackPanel Orientation="Vertical" >
                        <s:SurfaceButton Background="{StaticResource IconUndo }" Click="UndoStrokeSurfaceButtonClick" IsEnabled="{Binding Path=CanUndo}" Visibility="{Binding IsLowResolution, Converter={StaticResource ResourceKey=NotBoolVisibility}}"/>
                        <s:SurfaceButton Background="{StaticResource IconRedo }" Click="RedoStrokeButtonClick" IsEnabled="{Binding Path=CanRedo}" Visibility="{Binding IsLowResolution, Converter={StaticResource ResourceKey=NotBoolVisibility}}"/>
                        <s:SurfaceButton Background="{StaticResource InkStrokepencil }" Click="InkButtonClick"  BorderBrush="{Binding SelectedPaintType, Converter={StaticResource BorderBrushConverter}, ConverterParameter=Ink }" />
                        <s:SurfaceButton Background="{StaticResource InkLinePencil }" Click="LineButtonClick" BorderBrush="{Binding SelectedPaintType, Converter={StaticResource BorderBrushConverter}, ConverterParameter=Line }" />

                        <s:SurfaceButton Background="{StaticResource InkRectlange }" Click="RectangleButtonClick" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" BorderBrush="{Binding SelectedPaintType, Converter={StaticResource BorderBrushConverter}, ConverterParameter=Rectangle }" Visibility="{Binding IsLowResolution, Converter={StaticResource ResourceKey=NotBoolVisibility}}"  />
                        <s:SurfaceButton Background="{StaticResource InkSelect }" Click="SelectButtonClick" BorderBrush="{Binding SelectedPaintType, Converter={StaticResource BorderBrushConverter}, ConverterParameter=Select }" />
                        <s:SurfaceButton Background="{StaticResource InkEreaser }" Click="EreaserButtonClick" BorderBrush="{Binding SelectedPaintType, Converter={StaticResource BorderBrushConverter}, ConverterParameter=EraseByStroke }" />
                    </StackPanel>
                </GroupBox>


                <GroupBox  HorizontalAlignment="Left" Localization:Translate.Uid="Ink_Text" Header="{Localization:Translate Default=[AddText]}"  Visibility="{Binding IsLowResolution, Converter={StaticResource ResourceKey=NotBoolVisibility}}">
                    <StackPanel Orientation="Horizontal"  >
                        <s:SurfaceButton Background="{StaticResource InkText }" Click="TextButtonClick" BorderBrush="{Binding SelectedPaintType, Converter={StaticResource BorderBrushConverter}, ConverterParameter=Text }"  />
                        <CustomControl:ValidateTextBox x:Name="InkText" AcceptsReturn="True" MaxHeight="120" Width="150" Visibility="{Binding SelectedPaintType, Converter={StaticResource EnumVisibilityConverter}, ConverterParameter=Text }"  ValidateRegex=".+"/>
                        <s:SurfaceButton Background="{StaticResource IconDelete }" Click="TextCancelButtonClick" Visibility="{Binding SelectedPaintType, Converter={StaticResource EnumVisibilityConverter}, ConverterParameter=Text }"  />
                    </StackPanel> 
                </GroupBox>

                <GroupBox  HorizontalAlignment="Left" Localization:Translate.Uid="Ink_FullScreen" Header="{Localization:Translate Default=[FullScreen]}"  Visibility="{Binding IsFullScreenMode, Converter={StaticResource ResourceKey=NotBoolVisibility}}" >
                    <StackPanel Orientation="Horizontal">
                        <s:SurfaceButton Background="{StaticResource IconFullScreen}" Click="OnFullScreenClick" IsEnabled="{Binding Path=CanUndo, Converter={StaticResource NotBool}}"/>
                    </StackPanel>
                </GroupBox>

                <GroupBox  HorizontalAlignment="Left" Localization:Translate.Uid="Ink_Color" Header="{Localization:Translate Default=[Color]}" Visibility="{Binding IsLowResolution, Converter={StaticResource ResourceKey=NotBoolVisibility}}" >                    
                    <StackPanel Orientation="Horizontal">
                        <s:SurfaceButton Background="Black" Click="OnColorButtonClick"  Name="CurrentColor"/>                        
                    </StackPanel>                    
                </GroupBox>
                <Image HorizontalAlignment="Right" Visibility="Collapsed" Margin="0,0,0,0"  VerticalAlignment="Bottom" Stretch="Fill"  Width="54" Height="30"  Name="ColorWheel" Source="pack://application:,,,/ScrumTable.UI.View;component/Resources/ColorRay.png" RenderTransformOrigin="0,0"
                            MouseMove="OnColorWheelContactTap" MouseUp="OnColorWheelContactTap" MouseDown="OnColorSelectionPreviewContactDown"  TouchMove="OnColorWheelContactTap" TouchUp="OnColorWheelContactTap" TouchDown="OnColorSelectionPreviewContactDown" Grid.Column="1" >
                    <Image.RenderTransform>
                        <!-- Transform it so it extends beyond the borders of the grid -->
                        <TransformGroup>
                            <ScaleTransform ScaleX="4" ScaleY="2.6"/>
                        </TransformGroup>
                    </Image.RenderTransform>
                </Image>

   
            </StackPanel>
        </Grid>
    </Grid>
</UserControls:ScrumUserControl>
